package leetcode.medium.limit50;

/**
 * @author yaoyao1.liu@zhaopin.com.cn
 * @since 2022-11-09 15:59
 **/
public class No50 {

    public static void main(String[] args) {
        No50 no50 = new No50();
        double v = no50.myPow(2.1, 3);
        System.out.println(v);

    }
    public double myPow(double x, int n) {
        if (x == 1) {
            return 1;
        }
        if (n > 0) {
            double result = 1;
            for (int i = 0; i < n; i++) {
                result = result * x;
            }
            return result;
        } else if (n == 0) {
            if (x == 0) {
                return 0;
            } else {
                return 1;
            }
        } else {
            double result = 1;
            for (int i = 0; i < -n; i++) {
                result = result * x;
            }
            return 1 / result;
        }
    }

}
